<template>
  <div class="container">
    <div>
      <el-row :gutter="20">
        <el-col :span="6">
          <el-form ref="form" :model="form">
            <el-form-item label="查询方式：">
              <el-select
                v-model="form.queryType"
                placeholder="请选择"
              >
                <el-option
                  v-for="item in form.queryTypeList"
                  :key="item.index"
                  :label="item.label"
                  :value="item.value"
                ></el-option>
              </el-select>
            </el-form-item>
            
            <el-form-item label="查询区域：">
              <el-select
                v-model="form.clientName"
                placeholder="请选择"
              >
                <el-option
                  v-for="item in form.clientNameList"
                  :key="item.label"
                  :label="item.label"
                  :value="item.label"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-form>
        </el-col>
        <el-col :span="6">
          <el-form ref="form" :model="form">
            <el-form-item label="选择日期：">
              <el-date-picker
                v-model="form.valueDay"
                type="date"
                placeholder="选择日期"
                value-format="yyyy-MM-dd"
              ></el-date-picker>
            </el-form-item>

            <div v-if="this.form.queryType === 2"
              style="margin: -10px 0 10px 0; color: red; letter-spacing: 2px"
            >
              请选择查询周的周日!
            </div>
          </el-form>
        </el-col>

        <el-col :span="6">
          <el-form ref="form" :model="form" style="float: left">
            <el-button size="mini" type="primary" @click="getlistdata"
              >查 询</el-button
            >
            <el-button size="mini" type="success" @click="exportExcel"
              >导 出</el-button
            >
          </el-form>
        </el-col>
      </el-row>
      <!-- <el-row :gutter="0" style="margin-top: 20px; margin-bottom: 20px">
        <el-col :span="3" :offset="4">
          <span>{{ formInfo.all }}</span>
        </el-col>
        <el-col :span="3">
          <span>{{ formInfo.work }}</span>
        </el-col>
        <el-col :span="3">
          <span>{{ formInfo.one }}</span>
        </el-col>
        <el-col :span="3">
          <span>{{ formInfo.two }}</span>
        </el-col>
        <el-col :span="3">
          <span>{{ formInfo.three }}</span>
        </el-col>
      </el-row> -->
    </div>
    <el-table
      v-loading="loading"
      :data="
        tableData.slice((currentPage - 1) * pageSize, currentPage * pageSize)
      "
      highlight-current-row
    >
      <!-- ROADNAME	REMARKS	LWORK1	LWORKBFB1
道路名称	作业公司	作业长度（米）	百分比 -->
      <!-- <el-table-column prop="TITLE1" label="班组名称" align="center"></el-table-column> -->
      <el-table-column
        prop="序号"
        label="排名"
        align="center"
      ></el-table-column>
      <el-table-column
        prop="行政区"
        label="行政区"
        align="center"
      ></el-table-column>
      <el-table-column
        prop="主干作业率"
        label="一级道路作业率"
        align="center"
      ></el-table-column>
      <el-table-column
        prop="次干作业率"
        label="二级道路作业率"
        align="center"
      ></el-table-column>
      <el-table-column
        prop="支路作业率"
        label="三级道路作业率"
        align="center"
      ></el-table-column>
      <el-table-column
        prop="道路作业率"
        label="道路总作业率"
        align="center"
      ></el-table-column>
      <!-- <el-table-column label="操作" width="100">
        <template slot-scope="scope">
          <el-button type="text" icon="el-icon-info" @click="handleEdit(scope.$index, scope.row)">详情</el-button>
        </template>
      </el-table-column>-->
    </el-table>
    <div class="pagination">
      <el-pagination
        background
        layout="total, sizes, prev, pager, next, jumper"
        :current-page="currentPage"
        :page-size="pageSize"
        :total="tableData.length"
        @size-change="handleSizeChange"
        @current-change="handlePageChange"
      ></el-pagination>
    </div>
  </div>
</template>
<script>
import "@/assets/css/common.css";
import { formatDate } from "@/common/js/date.js";
import export2Excel from "@/utils/exportExcel/index.js";
export default {
  data () {
    return {
      currentPage: 1, //初始页
      pageSize: 10, //    每页的数据
      loading: false,
      form: {
        radioData: "日",
        valueDay: formatDate(
          new Date(new Date() - 3600 * 1000 * 24),
          "yyyy-MM-dd"
        ),
        valueMonth: "",
        queryType: 1,
        queryTypeList: [{
          value: 1,
          label: '按天查询'
        }, {
          value: 2,
          label: '按周查询'
        }],
        clientName: '全市',
        clientNameList: [{
          label: '全市'
        }, {
          label: '市内六区'
        }, {
          label: '环城四区'
        }, {
          label: '滨海新区'
        }, {
          label: '新五区'
        }],
      },
      formInfo: {
        all: "",
        work: "",
        one: "",
        two: "",
        three: "",
      },
      teamList: [],
      teamValue: "",
      tableData: [],
      groupingList: [],
      groupingNo: "",
    };
  },
  created () {
    this.getlistdata();
  },
  methods: {
    // 获得分组列表
    // async getGroupingList () {
    //   var url =
    //     "Vehicle/GetClientInfo?client_no=" + localStorage.getItem("CLIENT_NO"); // zxdata
    //   let { data } = await this.$Http.get(url);
    //   this.groupingList = data;
    //   this.groupingNo = data[0].CLIENT_GROUP_NO;
    //   this.getlistdata();
    // },
    async getlistdata () {
      this.currentPage = 1;
      var url =
        "Vehicle/GetRoadInfoResultAdmin?CLIENT_NO=" + this.form.clientName
        + "&WORKDATE=" + this.form.valueDay
        + "&TYPE=" + this.form.queryType;
      const { data } = await this.$Http.get(url);
      this.tableData = data;
      this.tableData.shift();
    },
    // 导出Excel
    exportExcel () {
      let excelName = "全市道路作业率统计";
      const tHeader = [
        "排名",
        "行政区",
        "一级道路作业率",
        "二级道路作业率",
        "三级道路作业率",
        "道路总作业率",
      ];
      const filterVal = [
        "排名",
        "行政区",
        "主干作业率",
        "次干作业率",
        "支路作业率",
        "道路作业率",
      ];
      export2Excel(tHeader, filterVal, this.tableData, excelName);
    },
    //详情
    handleEdit (index, row) {
      //   this.idx = index;
      //   this.form = row;
      //   this.editVisible = true;
    },
    // 分页导航
    handlePageChange (currentPage) {
      this.currentPage = currentPage;
      // console.log(this.currentPage)
      // this.$set(this.query, 'pageIndex', val);
      // this.getData();
    },
    handleSizeChange (size) {
      this.pageSize = size;
      console.log(this.pageSize);
    },
  },
};
</script>
<style>
.content {
  overflow-y: scroll;
}
.el-col-6 {
  min-width: 400px;
  min-height: 50px;
}
.el-table th {
  height: 40px;
}
</style>